#include "mtrand.h"
#include "TinkerCell3D.h"

/*
using namespace Tinkercell;
using namespace nTinker;

//
//	Entry points
//

static SetParamCmd setParamCmd;
static SimulateCmd simulateCmd;
static ComputeDensityCmd computeDensityCmd;

MStatus NTINKEREXPORT initializePlugin( MObject obj )
{
	MStatus   status;
	MFnPlugin plugin( obj, PLUGIN_COMPANY, "2011", "Any" );
	Animator::load();

	status = setParamCmd.registerCommand( obj );
	status = simulateCmd.registerCommand( obj );
	status = computeDensityCmd.registerCommand( obj );

	return status;
}

MStatus NTINKEREXPORT uninitializePlugin( MObject obj )
{
	MStatus status;
	MFnPlugin plugin( obj );
	Animator::unload();

	status = setParamCmd.deregisterCommand( obj );
	status = simulateCmd.deregisterCommand( obj );
	status = computeDensityCmd.deregisterCommand( obj );

	return status;
}
*/


/* Testing nParticles division of cells */

static QList<MnParticle*> particles;
static MnSolver * solver = 0;

void createParticles( MTime& time, void * clientData )
{
	if (!solver)
	{
		solver = new MnSolver;
		solver->setGravity(0.0);
		solver->createNSolver();
	}

	if (particles.isEmpty())
	{
		MnParticle * firstParticle = new MnParticle;
		firstParticle->setTopology(1);
		firstParticle->setDisableGravity(true);

		MFloatPointArray positions;
		positions.append(0.0,0.0);
		firstParticle->setPositions(positions);

		particles.append(firstParticle);
		solver->addNObject(firstParticle);
	}
	else
	{
		for (int i=0; i < particles.size(); ++i)
		{
			MnParticle * parentParticles = particles[i];
			MFloatPointArray parentPositions;
			particles[i]->getPositions(parentPositions);

			MnParticle * childParticles = new MnParticle;
			childParticles->setTopology(parentPositions.length());
			childParticles->setDisableGravity(true);

			MFloatPointArray childPositions;
			for (int i=0; i < parentPositions.length(); ++i)
			{
				MFloatPoint p = parentPositions[i];
				childPositions.append(p.x + mtrand()*2.0, p.y + mtrand()*2.0);
			}

			childParticles->setPositions(childPositions);
			particles.append(childParticles);
			solver->addNObject(childParticles);
		}
	}
}


MStatus NTINKEREXPORT initializePlugin( MObject obj )
{
	MFnPlugin plugin( obj, PLUGIN_COMPANY, "2011", "Any" );
	MDGMessage::addTimeChangeCallback(createParticles);
	return MStatus(MStatus::kSuccess);
}

MStatus NTINKEREXPORT uninitializePlugin( MObject obj )
{
	MFnPlugin plugin( obj );
	return MStatus(MStatus::kSuccess);
}


